<extend name="Base:dialog" />
<block name="dialog-header">
<h3>添加推荐</h3>
</block>
<block name="dialog-body">
<form role="form" name="form1" action="{:U('Recommend/add')}" method="post">
	<div class="form-group">
		<label for="title">推荐标题</label> <input type="text"
			class="form-control" name="title" id="title"
			placeholder="请输入推荐标题">
	</div>
	<div class="form-group">
		<label for="selectType">选择类型</label> 
		<div class="controls">
			<select name="type" id="selectType" class="form-control"
				data-rel="chosen" data-placeholder="请选择推荐类型">
				<option></option>
				<option value="Scenic">景区</option>
				<option value="Module">模块</option>
			</select>
		</div>
	</div>
	<div class="form-group">
		<label for="selectContent">选择推荐</label> 
		<div class="controls">
			<select name="content" id="selectContent" class="form-control"
				data-rel="chosen" data-placeholder="请选择推荐内容">
				<option></option>
				<foreach name="list" item="val" >
					<option value="{$val.id}">{$val.name}</option>
				</foreach>
			</select>
		</div>
	</div>
	<div class="form-group">
		<p class="center"><button type="submit" class="btn btn-primary">提交</button></p>
	</div>
</form>
<script type="text/javascript">
// 	$("#selectScenics option[value='SA42832886971446']").attr("selected","selected");  
	$('[data-rel="chosen"],[rel="chosen"]').chosen({
		no_results_text : "未找到此选项!", 
		width:"100%" 
		});
	$('#selectContents').change(function(){
		var checkText=$(this).find("option:selected").text();  //获取选择的内容
		var checkValue=$(this).val();  //获取选中的值
		console.log(checkText+":"+checkValue);
	});
	$('#selectType').change(function(){
		var checkText=$(this).find("option:selected").text();  //获取景区的名字
		var checkValue=$(this).val();  //获取获取的ID
// 		console.log(checkText+":"+checkValue);
		$.ajax({
            url : '__CONTROLLER__/getContent',
            data:{type:checkValue},
            cache : false, //是否缓存
            async : true,//是否异步
            type : "GET",
            dataType : 'json',
            success : function (result){
//                console.log(result);
               //将新景区的内容添加到景区下拉框里
               var string = "";
               for(i=0;i<result.length;i++){
            	   string+= "<option value=\""+result[i]['id']+"\">"+result[i]['name']+"</option>";
               }
               $('#selectContent').html(string);
               //更新景区下拉框
               $("#selectContent").trigger("chosen:updated");
            },
        })
	});
</script>
</block>